Step 14: Endpoint testing

Endpoint testing or API testing is a type of software testing that involves testing each API endpoint separately and independent from other endpoints (similar to unit testing) to ensure each endpoint meets expectations for functionality, reliability, performance, and security.

Create a subfolder routes in the tests folder. Moreover, add bookmarks.test.js to the routes subfolder with the following content:

import { describe, it } from "vitest";
import app from "../../src/index.js";
import supertest from "supertest";

const request = new supertest(app);

describe("Test API /bookmarks endpoints", () => {
  it("GET all bookmarks", async () => {});

  it("POST a bookmark", async () => {});

  it("GET a bookmark given its ID", async () => {});

  it("Update a bookmark given its ID", async () => {});

  it("Delete a bookmark given its ID", async () => {});
});

The file includes several placeholders for testing various API endpoints. Let’s update the first one as follows:

  it("GET all bookmarks", async () => {
    const response = await request.get("/bookmarks");
    expect(response.status).toBe(200);
  });

Run the tests in the bookmarks.test.js file.

Untitled

Save and commit all changes.